import Vue from 'vue'
import App from './App'
import { router } from './router/index'
import store from './store'
import iView from 'view-design'
import i18n from '@/locale'
import config from '@/config'
import axios from 'axios'
import 'echarts/theme/macarons.js';
import 'echarts/theme/vintage.js';
import 'echarts/theme/infographic.js';
import 'echarts/theme/shine.js';
import 'echarts/theme/roma.js';
import 'echarts/theme/dark.js';
import 'view-design/dist/styles/iview.css';
import './assets/icons/iconfont.css'
import './baseStyles/base.less'

import qs from 'qs'
import Enum from '@/libs/enum'

// 解决多次点击相同路由时报错问题 （报错信息：{_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/home") is not allowed",）
import Router from 'vue-router'
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

axios.defaults.baseURL = config.root
axios.defaults.withCredentials = true
axios.interceptors.request.use((config) => {
  config.data = qs.stringify(config.data)
  config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
  return config
}, (err) => {
  return Promise.reject(err)
})
Vue.prototype.store = store
Vue.prototype.axios = axios
Vue.prototype.rootUrl = config.root
Vue.prototype.Enum = Enum
Vue.use(iView, {
  i18n: (key, value) => i18n.t(key, value)
})
Vue.config.productionTip = false

Vue.prototype.$config = config

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router: router,
  i18n,
  store,
  axios,
  render: h => h(App)
})
